import bean.UrlSpit;
import util.CommonUtil;
import util.json.JsonMananger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Test {

    public static void main(String[] arg){
        Map<String,String[]> model = new HashMap<>();
        model.put("型号1",new String[]{"第1套","第2套","第3套","第4套","第5套","第6套"});
        model.put("型号2",new String[]{"第1套","第2套","第3套","第4套"});
        model.put("型号3",new String[]{"第1套","第2套"});


        Map<String,Integer[]> phone1 = new HashMap<>();
        phone1.put("型号1",new Integer[]{6,4,5,1,3,2});
        phone1.put("型号2",new Integer[]{3,4,2,1});
        phone1.put("型号3",new Integer[]{1,2});

        Map<String,Integer[]> phone2 = new HashMap<>();
        phone2.put("型号1",new Integer[]{5,6,3,1,4,2});
        phone2.put("型号2",new Integer[]{1,2,4,3});
        phone2.put("型号3",new Integer[]{2,1});


        Map<String,Integer[]> phone3 = new HashMap<>();
        phone3.put("型号1",new Integer[]{4,6,5,1,3,2});
        phone3.put("型号2",new Integer[]{2,1,4,3});
        phone3.put("型号3",new Integer[]{1,2});



        System.out.println("手机1显示的数据:");
        for(String key:phone1.keySet()){
            Integer[] ind = phone1.get(key);
            String[] taos = model.get(key);
            for(Integer i:ind){
                System.out.println(key+":"+taos[i-1]);
            }
        }

        System.out.println("手机2显示的数据:");
        for(String key:phone2.keySet()){
            Integer[] ind = phone2.get(key);
            String[] taos = model.get(key);
            for(Integer i:ind){
                System.out.println(key+":"+taos[i-1]);
            }
        }

        System.out.println("手机3显示的数据:");
        for(String key:phone3.keySet()){
            Integer[] ind = phone3.get(key);
            String[] taos = model.get(key);
            for(Integer i:ind){
                System.out.println(key+":"+taos[i-1]);
            }
        }

        System.out.println("手机1采集型号1 第二套");

    }

    public static void main2(String[] arg){
//        String url="https://apishyun.gree.com/api/sso/autoapp-default-server-greeshservice/api/WxAssignWay/reject";
//        System.out.println(url.substring(url.indexOf("/api/")+1));
//        UrlSpit urlSpit = CommonUtil.getUrlSpit(url);
//        System.out.println(JsonMananger.beanToJsonStr(urlSpit));
        String path="https://apishyun.gree.com/api/sso/autoapp-default-server-greeshservice/api/WxAssignWay/reject";
        if(path.contains("/api/")){
            path = path.substring(path.indexOf("/api/"));
            int index = path.lastIndexOf("/api/")+1;
            String domain = path.substring(0,index-1);
            path = path.substring(index);
            System.out.println(domain+","+path);
        }
    }
    public static void main1(String[] arg){
        String data = "89 00 28 00 32 13 93 10 06 27 00 34 32 19 08 00 20 01 42 04 09 A5 27 00 26 00 E0 00 25 33 D5 00 BC 05 DC 00 FF FF 0F 00 14 00 03 00 0A 00 47 0E DE 1D 3A 00 DD 23 25 11 E8 03 08 00 39 0C 4F 04 D0 32 9C 0B 2A 0F 3F 07 41 00 1F 00 82 06 A5 06 82 01 CA 00 80 05 80 00 34 33 AB 8A FF FF 5A 30 DE 03 8C 31 07 53 D8 3C 0A 00 71 1C AC 90 AC 0D 00 2C 94 02 14 00 2E 06 23 00 23 00 2A 00 20 03 40 01 80 0C A0 0F 68 42 74 40 74 40 93 00 00 00 BC 00 00 00 9F 03 37 01 BD 02 17 00 14 00 08 07 78 05 0C 00 0A 00 08 07 78 05 78 00 64 00 AC 0D 94 11 70 17 CC 0C 00 10 D7 13 07 00 7C 01 A9 03 FF 04 6A FF CC 0C 86 00 86 00 B9 00 B9 00 19 00 70 FE 00 02 94 11 05 00 D0 07 00 10 18 0E 78 05 78 05 00 19 18 17 F4 01 03 00 01 00 32 00 4B 00 28 00 0A 00 00 1A 00 2D 19 00 14 00 90 01 78 00 03 00 E3 FF 64 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 2C 00 2A 00 0A 0F B8 0B F0 0A 0A 00 08 00 30 00 01 00 01 00 82 00 00 00 2D 02 2E 00 B4 00 2E 00 78 00 14 00 B4 00 24 00 00 00 00 00 00 00 0C 00 46 00 64 00 3C 00 FE FF F9 FF F6 FF 08 00 06 00 04 00 03 00 03 00 0C 00 06 00 3C 00 46 00 37 00 0A 00 5A 00 A4 01 58 02 84 03 28 00 1E 00 52 03 16 03 8A 02 F4 01 70 03 16 03 8A 02 F4 01 86 01 14 00 44 00 2E 00 00 00 28 00 10 00 30 00 34 00 37 00 58 02 2B 00 24 00 3C 00 4C 00 2C 01 08 07 58 02 B0 04 0A 00 24 00 3C 00 4C 00 32 00 58 02 58 02 0A 00 05 00 2C 01 24 00 3C 00 60 00 22 00 28 00 3C 00 4E 00 00 00 00 00 05 00 00 00 FE FF 20 00 01 00 00 00 0D 00 0F 00 26 00 35 00 F4 00 2A 01 7C 01 2D 00 08 00 40 00 2E 00 0E 00 4E 00 1E 00 4E 00 2B 00 48 00 2E 00 24 00 32 00 1E 00 2A 00 0E 00 1D 00 3E 00 F6 FF 00 00 5C 00 6E 00 F6 FF 6C 00 FB FF 60 00 02 00 60 00 08 00 56 00 14 00 0C 00 1E 00 1E 00 18 00 0E 00 12 00 0E 00 0F 00 38 00 F1 FF 5A 00 46 00 48 00 4A 00 4C 00 38 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 52 00 54 00 56 00 58 00 5A 00 48 00 4A 00 4C 00 66 00 46 00 4E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5A 00 61 00 67 00 6E 00 73 00 07 00 05 00 03 00 01 00 00 00 34 00 37 00 3A 00 3E 00 40 00 30 00 37 00 3A 00 3E 00 40 00 52 00 58 00 5B 00 5D 00 60 00 30 00 02 00 0F 00 00 00 05 00 5F 00 6E 00 78 00 A0 00 6C 00 76 00 76 00 80 00 CE 01 1F 02 7A 02 DA 08 C7 11 55 15 E4 18 00 00 52 03 28 00 68 10 D8 0E A4 06 98 08 30 11 0A 00 0A 00 08 00 1B 00 41 00 08 00 1B 00 41 00 55 00 0A 00 0A 00 2A 00 52 00 6C 00 F0 00 7D 00 6E 00 D7 00 7D 00 6E 00 D7 00 0E 01 F0 00 69 00 5F 00 A5 00 AA 00 28 00 3C 00 3E 00 4E 00 3C 00 29 00 47 00 57 00 28 00 3B 00 38 00 50 00 55 00 02 00 02 00 02 00 04 00 02 00 02 00 04 00 04 00 02 00 02 00 02 00 04 00 04 00 00 00 00 00 04 00 04 00 0C 00 5A 00 5A 00 5A 00 16 00 2A 00 58 02 3C 00 7C 01 50 00 CC 01 0A 00 0C 00 06 00 46 00 46 00 46 00 02 00 13 00 7C 01 7C 01 7C 01 78 00 CC 01 28 00 5C 00 28 00 5C 00 FE FF 0F 00 2C 01 43 00 55 00 50 00 4B 00 4D 00 57 00 4C 00 47 00 43 00 32 00 28 00 32 00 2D 00 2D 00 43 00 58 00 58 00 57 00 57 00 57 00 56 00 51 00 46 00 33 00 29 00 30 00 2D 00 2D 00 44 00 4F 00 52 00 4F 00 4F 00 46 00 54 00 4F 00 3F 00 34 00 2A 00 2D 00 2D 00 2D 00 41 00 4D 00 4F 00 4D 00 4B 00 48 00 54 00 4F 00 49 00 36 00 2B 00 2D 00 2D 00 2D 00 32 00 32 00 3F 00 43 00 4A 00 52 00 50 00 50 00 4E 00 4B 00 49 00 48 00 32 00 32 00 3F 00 44 00 4C 00 4E 00 4E 00 4C 00 4B 00 48 00 46 00 41 00 34 00 36 00 3C 00 3D 00 48 00 4C 00 4C 00 4C 00 4B 00 48 00 46 00 41 00 36 00 38 00 39 00 3C 00 44 00 48 00 46 00 44 00 41 00 3F 00 3C 00 3C 00 02 00 03 00 78 00 2C 01 01 00 02 00 05 00 28 00 26 00 32 00 0D 00 26 00 20 00 20 00 5A 00 0F 00 0A 00 05 00 B8 0B 00 00 1E 00 26 00 1E 00 26 00 28 00 2B 00 10 00 00 00 3C 00 48 00 FB FF E9 FF 18 00 24 00 F6 FF 32 00 D2 00 DC 00 02 00 01 00 F1 FF 82 00 E6 00 5E 01 14 00 CD 00 78 00 34 00 38 00 14 00 3C 00 90 01 64 00 2D 00 E6 FF 54 00 3C 00 F6 FF FB FF 0A 00 05 00 1E 00 FE FF 1C 00 1E 00 FF FF 1C 00 18 00 21 00 04 00 02 00 04 00 0A 00 50 00 5C 00 5C 00 5C 00 06 00 0C 00 08 00 3C 00 14 00 06 00 3C 00 4B 00 F4 01 0A 00 90 01 5E 01 1E 00 5E 01 58 00 10 00 32 00 14 00 06 00 78 00 0A 00 04 00 44 00 12 00 96 00 FD FF FE FF FF FF 03 00 D2 00 28 00 20 00 34 00 25 00 22 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF";
        String[] datas = data.split(" ");
        int i = 0;
        String temp = "";
        List<String>  arr = new ArrayList<>();
        for(String s:datas){
            if(i==8){
                temp = temp.substring(0,temp.length()-1);
                arr.add(temp);
                i=0;
                temp = "";
            }
            temp +=s+" ";
            i++;
        }
        int j = 0 ;
        int f = 0 ;
        int n = 0;
        for(String a:arr){
            if(j>0&&j%32==0){
                j=0;
                n++;
            }
            f = j*8;
            String ff = Integer.toHexString(f).toUpperCase();
            String nn = Integer.toHexString(n).toUpperCase();
            if(nn.length()==1){
                nn="0"+nn;
            }
            if(ff.length()==1){
                ff = "0"+ff;
            }
            String result = nn+" "+ff+" "+a;
            System.out.println(result);
            result = result.replaceAll(" ","");
            byte[] b = HexStringToBinary(result);
            System.out.println("转换后："+BinaryToHexString(b));
            j++;
        }
        System.out.println(JsonMananger.beanToJsonStr(arr));

        String py = CommonUtil.getFirstPinyin("你好vip");
        System.out.println(py);

        String currentWdno = "34333MMM4";
        if(startWith(currentWdno,"X","S9")||endWith(currentWdno,"MMM4")){
            System.out.println("yes");
        }else{
            System.out.println("no");
        }

    }

    public static boolean startWith(String str,String ...regExp){
        return exp(str,true,regExp);
    }
    public static boolean endWith(String str,String ...regExp){
        return exp(str,false,regExp);
    }
    private static boolean exp(String str,boolean isStart,String ...regExp)
            throws PatternSyntaxException {
        String s = "";
        for(String st:regExp){
            if(isStart){
                s+=st+"([\\s\\S]*?)|";
            }else{
                s+=".*"+st+"$|";
            }
        }
        s = s.substring(0,s.length()-1);
        Pattern p = Pattern.compile(s);
        Matcher m = p.matcher(str);
        return m.matches();
    }
    private static String hexStr =  "0123456789ABCDEF";
    public static byte[] HexStringToBinary(String hexString){
        //hexString的长度对2取整，作为bytes的长度
        int len = hexString.length()/2;
        byte[] bytes = new byte[len];
        byte high = 0;//字节高四位
        byte low = 0;//字节低四位

        for(int i=0;i<len;i++){
            //右移四位得到高位
            high = (byte)((hexStr.indexOf(hexString.charAt(2*i)))<<4);
            low = (byte)hexStr.indexOf(hexString.charAt(2*i+1));
            bytes[i] = (byte) (high|low);//高地位做或运算
        }
        return bytes;
    }
    public static String BinaryToHexString(byte[] bytes){
        String result = "";
        String hex = "";
        for(int i=0;i<bytes.length;i++){
            //字节高4位
            hex = String.valueOf(hexStr.charAt((bytes[i]&0xF0)>>4));
            //字节低4位
            hex += String.valueOf(hexStr.charAt(bytes[i]&0x0F));
            result +=hex+" ";
        }
        return result;
    }
}
